package com.vnaloha.common.model;

/**
 * Class paging
 * @author hieu
 *
 */
public class Paging {
	
	private int page;
	private float totalRow;
	private int totalPerPage;
	private int startRow;
	private int maxPage;
	
	
	public Paging(int page, int totalRow, int totalPerPage) {
		this.page = page;
		this.totalRow = totalRow;
		this.totalPerPage = totalPerPage;
		
		caculatePage();
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public float getTotalRow() {
		return totalRow;
	}
	public void setTotalRow(float totalRow) {
		this.totalRow = totalRow;
	}
	public int getTotalPerPage() {
		return totalPerPage;
	}
	public void setTotalPerPage(int totalPerPage) {
		this.totalPerPage = totalPerPage;
	}
	public int getStartRow() {
		return startRow;
	}
	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}
	
	private void caculatePage() {
		int totalPage = (int) Math.ceil(totalRow/totalPerPage);
		page = page - 1;
		
		if(page > totalPage) {
			page = totalPage - 1;
		}
		
		if(page < 0) {
			page = 0;
		}
		
		startRow = page*totalPerPage;
		
		setStartRow(startRow);
		setMaxPage(totalPage);
		
	}
	public int getMaxPage() {
		return maxPage;
	}
	public void setMaxPage(int maxPage) {
		this.maxPage = maxPage;
	}
}
